home *** CD-ROM | disk | FTP | other *** search
/ The Best of Down Under Games / The Best of Down Under Games.iso / 3dfx Screen Savers / VoodooLights / Sources / cell_tp7.c < prev    next >
C/C++ Source or Header  |  1997-07-16  |  3KB  |  136 lines

  1. #include <stdlib.h>
  2. #include <glide.h>
  3.  
  4. #include "defines.h"
  5. #include "mat.h"
  6. #include "rgb.h"
  7. #include "tex.h"
  8. #include "cam.h"
  9. #include "cell.h"
  10. #include "cell_util.h"
  11. #include "cell_tp5.h"
  12. #include "cell_tp7.h"
  13.  
  14. static Bool first_init = True ;
  15. static GrMipMapId_t tp7_texture_src ;
  16.  
  17.  
  18. static void tp7_move_cell( Cell *c )
  19. {
  20.     mat_combv( dt, & c->vel, & c->pos, & c->pos ) ;
  21.     mat_combv( dt, & c->acc, & c->vel, & c->vel ) ;
  22.     cutl_limit_speed( c, c->max_speed ) ;
  23.     cutl_snap_pos_to_dad( c ) ;
  24. }
  25.  
  26. static void tp7_acc_cell(Cell *c) 
  27. {
  28.  
  29.     c->acc = xyz_Zero ;
  30.  
  31.     if(c->n_chld ) {
  32.     
  33.         Cell *son = c->children[0] ;
  34.         XYZ d ;
  35.         mat_subv( & son->pos, & c->pos, & d ) ;
  36.         mat_scalev( 0.2, & d, & c->acc ) ;
  37.     }
  38. }
  39.  
  40.  
  41. static void tp7_reproduce_cell( Cell *c) 
  42. {
  43.     if( c->generation < 15 ) c->children[ c->n_chld++ ] = ctp7_Constructor( c ) ;    
  44.     c->reproduce_cell = cell_menopause ; // nπo hß mais reproduτπo
  45. }
  46.  
  47. static void tp7_display_cell( Cell *c )
  48. {
  49.     Cell *dad = c->dad ;
  50.     XYZW pos, dpos ;
  51.     GrVertex vtx0, vtx1 ;
  52.  
  53.     if( ! dad ) return ;
  54.  
  55.     cam_W2P_XYZ( & c->pos, & pos ) ; 
  56.     cam_W2P_XYZ( & dad->pos, & dpos ) ; 
  57.  
  58.     if( clp_PointVisible( & pos ) && clp_PointVisible( & dpos )) {
  59.  
  60.         cam_XYZW2Vertex( & pos, & vtx0 ) ;
  61.         cam_XYZW2Vertex( & dpos, & vtx1 ) ;
  62.     
  63.         vtx0.r = c->color.r ;
  64.         vtx0.g = c->color.g ;
  65.         vtx0.b = c->color.b ;
  66.         vtx0.a = c->color.a ;
  67.  
  68.         vtx1.r = c->color.r ;
  69.         vtx1.g = c->color.g ;
  70.         vtx1.b = c->color.b ;
  71.         vtx1.a = c->color.a ;
  72.         vtx1.tmuvtx[0].sow = 128.0 * vtx1.oow ; 
  73.         vtx1.tmuvtx[0].tow = 128.0 * vtx1.oow ;
  74.  
  75.         grAADrawLine( & vtx0, &vtx1 ) ;    
  76.     } 
  77. }
  78.  
  79.  
  80.  
  81. void tp7_set_glide_state( void )
  82. {
  83.     if( first_init ) {
  84.         first_init = False ;
  85.         tp7_texture_src = tex_InitTexture("glow.3df") ;
  86.     }    
  87.     tex_SetTexSource( tp7_texture_src ) ;
  88.     grTexCombineFunction(GR_TMU0, GR_TEXTURECOMBINE_DECAL );
  89.     guColorCombineFunction( GR_COLORCOMBINE_TEXTURE_TIMES_ITRGB ) ;
  90.     guAlphaSource( GR_ALPHASOURCE_ITERATED_ALPHA );    
  91.     grAlphaBlendFunction( GR_BLEND_ONE, GR_BLEND_ONE, GR_BLEND_ONE, GR_BLEND_ZERO );
  92. }
  93.  
  94. Cell *ctp7_Constructor( Cell *dad )
  95. {
  96.  
  97.   Cell *c = cell_Constructor( CellType7 ) ;
  98.  
  99.   c->max_speed = dad->max_speed ;
  100.   c->dad = dad ;
  101.  
  102.   c->adulthood = 10.0 ;
  103.   c->size = 3.0 ;
  104.  
  105.   c->pos.x = dad->pos.x + 0.1 * ( 1 - 2 * rnd()) ;
  106.   c->pos.y = dad->pos.y + 0.1 * ( 1 - 2 * rnd()) ;
  107.   c->pos.z = dad->pos.z + 0.1 * ( 1 - 2 * rnd()) ;
  108.  
  109.   c->generation = dad->generation + 1 ;
  110.   
  111.   c->color.r = 10.0 ;
  112.   c->color.g = 100.0 ;
  113.   c->color.b = 255.0 ;
  114.   c->color.a = 255.0 ;
  115.  
  116.  
  117.   c->sparkle = 1.0 ;
  118.  
  119.    
  120.   c->move_cell = tp7_move_cell ;
  121.   c->acc_cell = tp7_acc_cell ;
  122.   c->reproduce_cell = tp7_reproduce_cell ;
  123.   c->display_cell = tp7_display_cell ;
  124.   return c ;
  125. }  
  126.     
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.     
  135.  
  136.